﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.Data;

namespace Pujcovna
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            new Loading.Loading().ShowDialog();
          //  userToolbar.ChangedData += userToolbar_ChangedData;
            userToolbar.NewUser += userToolbar_NewUser;
            userToolbar.AddedUser += userToolbar_AddedUser;
            lstData.ChangedItems += lstData_ChangedItems;
            textBoxesSearch.ChangedSearchedText += textBoxesSearch_ChangedSearchedText;
            
        }

        void userToolbar_AddedUser(object sender, AddUserLib.NovaZakazkaEventArgs e)
        {
            lstData.RefreshContent();
            statusBar.Content = "Přidána zakázka";
        }

        void userToolbar_AddedUser(object sender)
        {
                RefreshInfo();
        }

        private void RefreshGUI()
        {
           
            lstData.RefreshContent();
            RefreshInfo();
        }

        void lstData_ChangedItems(object sender)
        {
            RefreshGUI();
            RefreshInfo();
        }

        void textBoxesSearch_ChangedSearchedText(object sender, SmallControls.ChangedSearchTextArgs e)
        {
            lstData.Search(e.searchedText,e.table);
        }

        void userToolbar_NewUser(object sender)
        {
            SettingsLib.Settings.ID++;
        }

        void userToolbar_ChangedData(object sender)
        {
            lstData.RefreshContent();
         //   simpleInfo.UpdateInfo();
        }

        private void btnAddUser_Click(object sender, RoutedEventArgs e)
        {
        }

        private void Header_Loaded_1(object sender, RoutedEventArgs e)
        {
           
            
        }
        private void MainWindow_Loaded_1(object sender, RoutedEventArgs e)
        {
            RefreshGUI();
            RefreshInfo();
        }

        private void simpleInfo_Loaded(object sender, RoutedEventArgs e)
        {
            RefreshInfo();
        }

      
        private void userToolbar_Loaded(object sender, RoutedEventArgs e)
        {

        }

        public void RefreshInfo()
        {           
            lblPujceno.Content = lstData.GetListView().Items.Count;
            lblOpozdene.Content = lstData.GetCountExpiredItems();
        }

        private void Window_Closed_1(object sender, EventArgs e)
        {
           
        }

        private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = MessageBoxResult.Yes !=
                                    MessageBox.Show("Opravdu chcete ukončit program", "Upozornění", MessageBoxButton.YesNo,
                                                    MessageBoxImage.Warning);
            Application.Current.Shutdown();
        }
    }
}
